package com.moly.websocketone.configuration.filter;

import com.moly.websocketone.filter.TestFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:  注册 过滤器
 * @Author: m01
 * @Date: created at  2018/11/13  14:57
 * @Modified By:
 */
@Configuration
public class RegisteryFilter {

    @Bean
    public FilterRegistrationBean registrationTestFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();

        filterRegistrationBean.setFilter(testFilter());
        filterRegistrationBean.setName("testfilter");
        filterRegistrationBean.setOrder(10);

        List<String> urlPatterns = new ArrayList<>(1);
        urlPatterns.add("/*");
        filterRegistrationBean.setUrlPatterns(urlPatterns);

        return filterRegistrationBean;

    }

    @Bean
    public TestFilter testFilter(){
        return new TestFilter();
    }

}
